<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('尽调清单') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('业务类型')" prop="businessType">
        <el-input
          v-model="queryParams.businessType"
          :placeholder="$t('业务类型')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('创建时间')" prop="createTime">
        <DatePicker v-model="createTimes" type="daterange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="dealDdList" border :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <!--<el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>-->
      <el-table-column :label="$t('业务类型')" align="center" prop="businessType">
        <template slot-scope="scope">
          <span class="link-type" @click="showHandle(scope.row)">{{ scope.row.businessType }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('尽调项个数')" align="center" prop="ddItemNumber" />
      <el-table-column :label="$t('创建人')" align="center" prop="createBy.nickName" />
      <el-table-column :label="$t('创建时间')" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改尽调清单对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealDdForm ref="dealDdForm" />
    </el-dialog>
    <el-dialog :title="$t(title)" :visible.sync="ddListIndexOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogView" append-to-body @close="getList">
      <dealDdListIndex ref="dealDdListIndex" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealDd, delDealDd, exportDealDd } from '@/api/deal/dd/dealDd'
import dealDdForm from './dealDdForm.vue'
import dealDdListIndex from '@/views/deal/dd/dealDdListIndex'
export default {
    components: {
        dealDdForm,
        dealDdListIndex
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 尽调清单表格数据
          dealDdList: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
          // 显示尽调项层
          ddListIndexOpen: false,
          // 创建时间 查询参数
          createTimes: undefined,
          // 查询参数
          queryParams: {
              dealId: this.$route.query.id,
              businessType: undefined,
              createTime: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          }
      }
  },
  created() {
      this.getList()
  },
  methods: {
    /** 查询尽调清单列表 */
    getList() {
        this.loading = true
        listDealDd(this.addDateRange(this.queryParams, this.createTimes)).then(response => {
            this.dealDdList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            businessType: undefined,
            ddItemNumber: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.createTimes = undefined
        this.queryHandle()
    },
    showHandle(row) {
      this.ddListIndexOpen = true
      this.title = '尽调项'
      this.$nextTick(() => {
        this.$route.params.ddId = row.id
        this.$refs.dealDdListIndex.ddItemList()
      })
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.title = '尽调清单'
      this.$nextTick(() => {
        this.$refs.dealDdForm.init()
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = '尽调清单'
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealDdForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delDealDd(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return exportDealDd(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(function() {
        })
    }
  }
}
</script>
